
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/combinatorics/partitions.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:26:04 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Partitions &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="partitions.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Permutations" href="permutations.html" />
    <link rel="prev" title="Combinatorics" href="index.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="permutations.html" title="Permutations"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Combinatorics"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Combinatorics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Partitions</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.combinatorics.partitions">
<span id="partitions"></span><span id="combinatorics-partitions"></span><h1>Partitions<a class="headerlink" href="#module-sympy.combinatorics.partitions" title="Permalink to this headline">¶</a></h1>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.Partition">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.partitions.</span></span><span class="sig-name descname"><span class="pre">Partition</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">partition</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L12-L302"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.Partition" title="Permalink to this definition">¶</a></dt>
<dd><p>This class represents an abstract partition.</p>
<p>A partition is a set of disjoint sets whose union equals a given set.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.partitions" title="sympy.utilities.iterables.partitions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.partitions</span></code></a>, <a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.multiset_partitions" title="sympy.utilities.iterables.multiset_partitions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.multiset_partitions</span></code></a></p>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.Partition.RGS">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">RGS</span></span><a class="headerlink" href="#sympy.combinatorics.partitions.Partition.RGS" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the “restricted growth string” of the partition.</p>
<p class="rubric">Explanation</p>
<p>The RGS is returned as a list of indices, L, where L[i] indicates
the block in which element i appears. For example, in a partition
of 3 elements (a, b, c) into 2 blocks ([c], [a, b]) the RGS is
[1, 1, 0]: “a” is in block 1, “b” is in block 1 and “c” is in block 0.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">Partition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Partition</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">members</span>
<span class="go">(1, 2, 3, 4, 5)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">RGS</span>
<span class="go">(0, 0, 1, 2, 2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">+</span> <span class="mi">1</span>
<span class="go">Partition({3}, {4}, {5}, {1, 2})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">RGS</span>
<span class="go">(0, 0, 1, 2, 3)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.Partition.from_rgs">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">from_rgs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rgs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">elements</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L266-L302"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.Partition.from_rgs" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a set partition from a restricted growth string.</p>
<p class="rubric">Explanation</p>
<p>The indices given in rgs are assumed to be the index
of the element as given in elements <em>as provided</em> (the
elements are not sorted by this routine). Block numbering
starts from 0. If any block was not referenced in <code class="docutils literal notranslate"><span class="pre">rgs</span></code>
an error will be raised.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">Partition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Partition</span><span class="o">.</span><span class="n">from_rgs</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="nb">list</span><span class="p">(</span><span class="s1">&#39;abcde&#39;</span><span class="p">))</span>
<span class="go">Partition({c}, {a, d}, {b, e})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Partition</span><span class="o">.</span><span class="n">from_rgs</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="nb">list</span><span class="p">(</span><span class="s1">&#39;cbead&#39;</span><span class="p">))</span>
<span class="go">Partition({e}, {a, c}, {b, d})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Partition</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Partition</span><span class="o">.</span><span class="n">from_rgs</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">RGS</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">members</span><span class="p">)</span>
<span class="go">Partition({2}, {1, 4}, {3, 5})</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.Partition.partition">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">partition</span></span><a class="headerlink" href="#sympy.combinatorics.partitions.Partition.partition" title="Permalink to this definition">¶</a></dt>
<dd><p>Return partition as a sorted list of lists.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">Partition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Partition</span><span class="p">([</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span><span class="o">.</span><span class="n">partition</span>
<span class="go">[[1], [2, 3]]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.Partition.rank">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">rank</span></span><a class="headerlink" href="#sympy.combinatorics.partitions.Partition.rank" title="Permalink to this definition">¶</a></dt>
<dd><p>Gets the rank of a partition.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">Partition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Partition</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">rank</span>
<span class="go">13</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.Partition.sort_key">
<span class="sig-name descname"><span class="pre">sort_key</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L90-L115"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.Partition.sort_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a canonical key that can be used for sorting.</p>
<p>Ordering is based on the size and sorted elements of the partition
and ties are broken with the rank.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.iterables</span> <span class="kn">import</span> <span class="n">default_sort_key</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">Partition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Partition</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Partition</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">Partition</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Partition</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="n">d</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">a</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">c</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">default_sort_key</span><span class="p">);</span> <span class="n">l</span>
<span class="go">[Partition({1, 2}), Partition({1}, {2}), Partition({1, x}), Partition({3, 4}), Partition({0, 1, 2, 3})]</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.IntegerPartition">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.partitions.</span></span><span class="sig-name descname"><span class="pre">IntegerPartition</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">partition</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">integer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L305-L576"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.IntegerPartition" title="Permalink to this definition">¶</a></dt>
<dd><p>This class represents an integer partition.</p>
<p class="rubric">Explanation</p>
<p>In number theory and combinatorics, a partition of a positive integer,
<code class="docutils literal notranslate"><span class="pre">n</span></code>, also called an integer partition, is a way of writing <code class="docutils literal notranslate"><span class="pre">n</span></code> as a
list of positive integers that sum to n. Two partitions that differ only
in the order of summands are considered to be the same partition; if order
matters then the partitions are referred to as compositions. For example,
4 has five partitions: [4], [3, 1], [2, 2], [2, 1, 1], and [1, 1, 1, 1];
the compositions [1, 2, 1] and [1, 1, 2] are the same as partition
[2, 1, 1].</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.partitions" title="sympy.utilities.iterables.partitions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.partitions</span></code></a>, <a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.multiset_partitions" title="sympy.utilities.iterables.multiset_partitions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.multiset_partitions</span></code></a></p>
</div>
<p class="rubric">References</p>
<p><a class="reference external" href="https://en.wikipedia.org/wiki/Partition_(number_theory)">https://en.wikipedia.org/wiki/Partition_%28number_theory%29</a></p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.IntegerPartition.as_dict">
<span class="sig-name descname"><span class="pre">as_dict</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L485-L501"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.IntegerPartition.as_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the partition as a dictionary whose keys are the
partition integers and the values are the multiplicity of that
integer.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">IntegerPartition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">IntegerPartition</span><span class="p">([</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="mi">3</span> <span class="o">+</span> <span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
<span class="go">{1: 3, 2: 1, 3: 4}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.IntegerPartition.as_ferrers">
<span class="sig-name descname"><span class="pre">as_ferrers</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">char</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'#'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L560-L573"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.IntegerPartition.as_ferrers" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints the ferrer diagram of a partition.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">IntegerPartition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">IntegerPartition</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span><span class="o">.</span><span class="n">as_ferrers</span><span class="p">())</span>
<span class="go">#####</span>
<span class="go">#</span>
<span class="go">#</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.IntegerPartition.conjugate">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">conjugate</span></span><a class="headerlink" href="#sympy.combinatorics.partitions.IntegerPartition.conjugate" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the conjugate partition of itself.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">IntegerPartition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">IntegerPartition</span><span class="p">([</span><span class="mi">6</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">conjugate</span>
<span class="go">[5, 4, 3, 1, 1, 1]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.IntegerPartition.next_lex">
<span class="sig-name descname"><span class="pre">next_lex</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L435-L483"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.IntegerPartition.next_lex" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the next partition of the integer, n, in lexical order,
wrapping around to [n] if the partition is [1, …, 1].</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">IntegerPartition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">IntegerPartition</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">next_lex</span><span class="p">())</span>
<span class="go">[4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">partition</span> <span class="o">&lt;</span> <span class="n">p</span><span class="o">.</span><span class="n">next_lex</span><span class="p">()</span><span class="o">.</span><span class="n">partition</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.IntegerPartition.prev_lex">
<span class="sig-name descname"><span class="pre">prev_lex</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L398-L433"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.IntegerPartition.prev_lex" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the previous partition of the integer, n, in lexical order,
wrapping around to [1, …, 1] if the partition is [n].</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">IntegerPartition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">IntegerPartition</span><span class="p">([</span><span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">prev_lex</span><span class="p">())</span>
<span class="go">[3, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">partition</span> <span class="o">&gt;</span> <span class="n">p</span><span class="o">.</span><span class="n">prev_lex</span><span class="p">()</span><span class="o">.</span><span class="n">partition</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.random_integer_partition">
<span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.partitions.</span></span><span class="sig-name descname"><span class="pre">random_integer_partition</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L579-L615"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.random_integer_partition" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates a random integer partition summing to <code class="docutils literal notranslate"><span class="pre">n</span></code> as a list
of reverse-sorted integers.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">random_integer_partition</span>
</pre></div>
</div>
<p>For the following, a seed is given so a known value can be shown; in
practice, the seed would not be given.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">random_integer_partition</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">85</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="go">[85, 12, 2, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">random_integer_partition</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="go">[5, 3, 1, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">random_integer_partition</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="go">[1]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.RGS_generalized">
<span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.partitions.</span></span><span class="sig-name descname"><span class="pre">RGS_generalized</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">m</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L618-L647"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.RGS_generalized" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the m + 1 generalized unrestricted growth strings
and returns them as rows in matrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">RGS_generalized</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">RGS_generalized</span><span class="p">(</span><span class="mi">6</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[  1,   1,   1,  1,  1, 1, 1],</span>
<span class="go">[  1,   2,   3,  4,  5, 6, 0],</span>
<span class="go">[  2,   5,  10, 17, 26, 0, 0],</span>
<span class="go">[  5,  15,  37, 77,  0, 0, 0],</span>
<span class="go">[ 15,  52, 151,  0,  0, 0, 0],</span>
<span class="go">[ 52, 203,   0,  0,  0, 0, 0],</span>
<span class="go">[203,   0,   0,  0,  0, 0, 0]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.RGS_enum">
<span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.partitions.</span></span><span class="sig-name descname"><span class="pre">RGS_enum</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">m</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L650-L684"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.RGS_enum" title="Permalink to this definition">¶</a></dt>
<dd><p>RGS_enum computes the total number of restricted growth strings
possible for a superset of size m.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">RGS_enum</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">Partition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">RGS_enum</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="go">15</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">RGS_enum</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">52</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">RGS_enum</span><span class="p">(</span><span class="mi">6</span><span class="p">)</span>
<span class="go">203</span>
</pre></div>
</div>
<p>We can check that the enumeration is correct by actually generating
the partitions. Here, the 15 partitions of 4 items are generated:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Partition</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">20</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">s</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">a</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">==</span> <span class="mi">15</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.RGS_unrank">
<span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.partitions.</span></span><span class="sig-name descname"><span class="pre">RGS_unrank</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rank</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L687-L719"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.RGS_unrank" title="Permalink to this definition">¶</a></dt>
<dd><p>Gives the unranked restricted growth string for a given
superset size.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">RGS_unrank</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">RGS_unrank</span><span class="p">(</span><span class="mi">14</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">[0, 1, 2, 3]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">RGS_unrank</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">[0, 0, 0, 0]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.combinatorics.partitions.RGS_rank">
<span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.partitions.</span></span><span class="sig-name descname"><span class="pre">RGS_rank</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rgs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/partitions.py#L722-L742"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.partitions.RGS_rank" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the rank of a restricted growth string.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.partitions</span> <span class="kn">import</span> <span class="n">RGS_rank</span><span class="p">,</span> <span class="n">RGS_unrank</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">RGS_rank</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="go">42</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">RGS_rank</span><span class="p">(</span><span class="n">RGS_unrank</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">7</span><span class="p">))</span>
<span class="go">4</span>
</pre></div>
</div>
</dd></dl>

</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="index.html"
                        title="previous chapter">Combinatorics</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="permutations.html"
                        title="next chapter">Permutations</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/combinatorics/partitions.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="permutations.html" title="Permutations"
             >next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Combinatorics"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Combinatorics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Partitions</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/combinatorics/partitions.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:26:04 GMT -->
</html>